package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesEquipmentRepair;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesEquipmentRepairDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:26:09
 */
public class MesEquipmentRepairConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesEquipmentRepairConverts.class);

    public static List<MesEquipmentRepairDTO> convert(List<MesEquipmentRepair> mesEquipmentRepairList) {
        if (CollectionUtils.isEmpty(mesEquipmentRepairList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesEquipmentRepairDTO> mesEquipmentRepairListResult = Lists.newArrayList();
        for (MesEquipmentRepair mesEquipmentRepair : mesEquipmentRepairList) {
            mesEquipmentRepairListResult.add(convert(mesEquipmentRepair));
        }
        return mesEquipmentRepairListResult;
    }

    public static MesEquipmentRepairDTO convert(MesEquipmentRepair mesEquipmentRepair) {
        try {
            return BeanUtils.copy(mesEquipmentRepair, MesEquipmentRepairDTO.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentRepair到MesEquipmentRepairDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentRepair到MesEquipmentRepairDTO转换失败", e);
        }
    }

    public static MesEquipmentRepair convert(MesEquipmentRepairDTO mesEquipmentRepairDTO) {
        try {
            return BeanUtils.copy(mesEquipmentRepairDTO, MesEquipmentRepair.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentRepairDTO到MesEquipmentRepair转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentRepairDTO到MesEquipmentRepair转换失败", e);
        }
    }
}